package com.motong.gongdan.config.mongo;

import com.mongodb.client.MongoDatabase;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.core.MongoTemplate;

import javax.annotation.PostConstruct;

/**
 * @author:fff
 * @time:2022/7/13
 */
public class DynamicMongoTemplate extends MongoTemplate {
    

    public DynamicMongoTemplate(MongoDatabaseFactory mongoDbFactory) {
        super(mongoDbFactory);
    }

    @PostConstruct
    public void afterPropertiesSet(){

    }

    @Override
    protected MongoDatabase doGetDatabase(){
        MongoDatabaseFactory mongoDatabaseFactory = MongoContext.getMongoDbFactory();
        return mongoDatabaseFactory.getMongoDatabase();
    }
}
